import HelloApp.*;
import org.omg.CosNaming.*;
//import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;

public class HelloClient
{
  static Hello helloImpl;
  
  private static String[] defaultArgs(){
	  String args[] = new String[4];
	  args[1] = "-ORBInitialPort";
	  args[2] = "2056";
	  args[3] = "-ORBInitialHost";
	  args[4] = "SR1.iki.his.se";
	  
	  return args;
  }

  public static void main(String args[])
    {
      try{
    	  ORB orb = null;
    	  // create and initialize the ORB
    	  if(args.length > 0)    		  
    		  orb = ORB.init(args, null);
    	  else
    		  orb = ORB.init(defaultArgs(), null);	// Orka skriva -ORBInitialPort 2056 -ORBInitialHost SR1.iki.his.se hela tiden!

        // get the root naming context
        org.omg.CORBA.Object objRef = 
	    orb.resolve_initial_references("NameService");
        // Use NamingContextExt instead of NamingContext. This is 
        // part of the Interoperable naming Service.  
        NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
 
        // resolve the Object Reference in Naming
        String name = "HelloServer007";
        helloImpl = HelloHelper.narrow(ncRef.resolve_str(name));      
        
        
        // TODO: Hej svejs!
        System.out.println("Obtained a handle on server object: " + helloImpl);
        System.out.println(helloImpl.sayHello());
        
        System.out.println("Result of 2 + 3 = " + helloImpl.addition(2,3));
        
        IntHolder a = new IntHolder(25);
        IntHolder b = new IntHolder(10);
        
        System.out.print("Division " + a.value + "/" + b.value + " = ");
        helloImpl.division(a, b);        
        System.out.println(a.value + "qu " + b.value + "rem");
        
        ShoeUser user = helloImpl.createUser("Jimmy", 43);
        if(user != null)
            System.out.println("New user " + user.name + " with shoe size " + user.foot_size+ " created");
        else
           System.out.println("Error creating user");
        
        
        helloImpl.shutdown();       
	} catch (Exception e) {
          System.out.println("ERROR : " + e) ;
	  e.printStackTrace(System.out);
	  }
    }

}
